package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 动态查询购物车数据
     * @param shoppingCart
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 修改数量
     * @param cart
     */
    @Update("update shopping_cart set number = #{number} where id =#{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * 添加购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) VALUE " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 查看购物车
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{user_id}")
    List<ShoppingCart> getByUserId(Long userId);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("DELETE from shopping_cart where user_id =#{user_id}")
    void deleteAll(Long userId);

    /**
     * 删除购物车里的某一个物品
     * @param shoppingCart
     */
    void delete(ShoppingCart shoppingCart);


    /**
     * 批量插入购物车数据
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
